<?php
// error_reporting(E_ALL);
// ini_set("display_errors","On");

//就近 www.jiujin.me
if (!defined('IN_IA')) {
	die('Access Denied');
}
global $_W, $_GPC;
$id=$_GPC['log_id'];
$openid = m('user')->getOpenid();
$member = m('member')->getInfo($openid);
$mid=$member['id'];
if(!empty($_POST['id'])){
  $info=pdo_fetch('select * from'.tablename('mc_members').' where uniacid=:uniacid and uid=:uid',array(':uniacid'=>$_W['uniacid'],':uid'=>$member['uid']));
  $log=pdo_fetch('select * from'.tablename('ewei_shop_commission_gift_log').' where uniacid=:uniacid and id=:id',array(':uniacid'=>$_W['uniacid'],':id'=>$_POST['id']));
  if(empty($log)){
     exit; 
  }
  
  $money=$info['gift_card']+$log['money'];
  pdo_update('ewei_shop_commission_gift_log',array('status'=>1,'gettime'=>time(),'openid'=>$member['openid']),array('uniacid'=>$_W['uniacid'],'id'=>$_POST['id']));
  pdo_update('mc_members',array('gift_card'=>$money),array('uniacid'=>$_W['uniacid'],'uid'=>$member['uid']));
}
        $row=pdo_fetch('select * from'.tablename('ewei_shop_commission_gift_log').' where uniacid=:uniacid and id=:id',array(':uniacid'=>$_W['uniacid'],':id'=>$id));
        if(empty($row)){
         exit;   
        }
        $style=pdo_fetch('select * from'.tablename('ewei_shop_commission_gift_style').' where uniacid=:uniacid and id=:id',array(':uniacid'=>$_W['uniacid'],':id'=>$row['style']));
        if($style){
         $style['overtime']=date('Y-m-d',$style['endtime']);   
        }
        $access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx4d6a0644cae71c05&secret=e57902975056e739bae60ae12c6c1419";
        $access_msg = json_decode(file_get_contents($access_token));
        $token = $access_msg->access_token;
        $subscribe_msg = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$token&openid=$_W[openid]";
        $subscribe = json_decode(file_get_contents($subscribe_msg));
        $gzxx = $subscribe->subscribe;
            $userinfo= pdo_fetch("SELECT * FROM " . tablename('ewei_shop_member') . " WHERE uid = '{$member['uid']}' and uniacid = '{$_W['uniacid']}'");
            if(empty($userinfo['realname']) || empty($userinfo['mobile']) || empty($userinfo['weixin']) || empty($userinfo['province']) || empty($userinfo['city'])){
                 if($gzxx === 1 && $_GPC['xiaodian'] != $mid){
                 $url="http://wx.lanxuevip.com/app/index.php?i=5&c=entry&p=info&do=member&saoma=true&m=ewei_shop&xiaodian=".$_GPC['xiaodian']."&log_id=".$_GPC['log_id'];
                 header("Location: $url");
                 exit;
                 }
            }
include $this->template('gift/list');

